package com.xiao.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiao.common.dto.UserDto;
import com.xiao.dao.UserIDMappe;
import com.xiao.pojo.Userid;
import com.xiao.server.UserloginServer;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserloginServerImpl implements UserloginServer {
    @Autowired
    private UserIDMappe userIDMappe;

    @Override
//    登录功能
    public Boolean login(Userid userID) {
        Boolean islogin = false;
        Userid userID1 = userIDMappe.selectById(userID.getUserId());
        if (userID1 == null){
            return islogin;
        }
        if (userID.getPassword() == userID1.getPassword()) {
            islogin = true;
            return islogin;
        }else {
            return islogin;
        }
    }

    @Override//注册
    public void logon(Userid userID) {
        Userid userID1 = userIDMappe.selectById(userID.getUserId());
        if (userID1 == null){
            userIDMappe.insert(userID);
        }

    }

    @Override//登录
    public UserDto login(UserDto userDto) {
        QueryWrapper<Userid> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_ID", userDto.getUserId());
        queryWrapper.eq("password", userDto.getPassword());
        List<Userid> list = userIDMappe.selectList(queryWrapper);
        if (list.size() != 0){
            BeanUtils.copyProperties(list.get(0), userDto);
            userDto.setPassword(" ");
            return userDto;
        }else {
            return null;
        }
    }
}
